/**
 * 
 */
package com.easidea.tim.entity.system.orgnization;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Where;
import org.springside.core.dao.extend.Undeletable;

import com.easidea.tim.entity.BaseEntity;
import com.easidea.tim.entity.system.Geography;

/**
 * @author Harrison
 *
 */
@Entity(name="tim_orgnization_department")
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Cache(region="tim_orgnization_department",usage=CacheConcurrencyStrategy.READ_WRITE)
@Undeletable(status="deleted")
public class Department extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7134170944493203919L;
	
	private String name;
	private Geography area; // 所属地区
	private Department parentDept; // 上级部门
	private List<Department> sonList; // 下属部门列表
	
	/**
	 * @return the name
	 */
	@Column(name="name", nullable=false)
	public String getName() {
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return the area
	 */
	@OneToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="area_id", nullable=false)
	public Geography getArea() {
		return area;
	}
	/**
	 * @param area the area to set
	 */
	public void setArea(Geography area) {
		this.area = area;
	}
	/**
	 * @return the parentDept
	 */
	@OneToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="parent_dept_id",nullable=true)
	public Department getParentDept() {
		return parentDept;
	}
	/**
	 * @param parentDept the parentDept to set
	 */
	public void setParentDept(Department parentDept) {
		this.parentDept = parentDept;
	}
	
	/**
	 * 
	 * @return
	 */
	@OneToMany(fetch=FetchType.LAZY,mappedBy="parentDept")
	@Where(clause="deleted <> 1")
	public List<Department> getSonList() {
		return sonList;
	}
	
	/**
	 * 
	 * @param sonList
	 */
	public void setSonList(List<Department> sonList) {
		this.sonList = sonList;
	}
	

}
